package com.tang.netty.bio.server;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

@Slf4j
public class BioServer extends Thread {

    private ServerSocket serverSocket = null;

    public static void main(String[] args) {
        BioServer bioServer = new BioServer();
        bioServer.start();
    }

    @Override
    public void run() {
        try {
            serverSocket = new ServerSocket();
            serverSocket.bind(new InetSocketAddress(7397));
            log.info("bio server start done!");
            while (true) {
                Socket accept = serverSocket.accept();
                BioServerHandler bioServerHandler = new BioServerHandler(accept, StandardCharsets.UTF_8);
                bioServerHandler.start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
}
